package org.lee.hello.delegate;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.MethodDelegation;

import static net.bytebuddy.matcher.ElementMatchers.named;

/**
 * @author jackielee
 * @version 1.0
 * @description DelegateDemo
 * @date 2021/7/28
 **/
public class DelegateDemo {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException {

        String hello = new ByteBuddy()
                .subclass(Source.class)
                .method(named("hello")).intercept(MethodDelegation.to(Target.class))
                .make()
                .load(DelegateDemo.class.getClassLoader())
                .getLoaded()
                .newInstance()
                .hello("lee");
        System.out.println(hello);
    }
}

